const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

const db=cloud.database();

exports.main = async (event, context) => {
  const {account,family_background,political_thought,learning_condition,innovation_ability,social_practice,mixed_ability}=event.data;
  try{
    const repeat=await db.collection("student").where(
      {
        account:account
      }
    ).get();
    if(repeat.data.length==1){
      try{
        const up=await db.collection("student").where({
          account:account
        }).update({
          data:{
            family_background:family_background,
            political_thought:political_thought,
            learning_condition:learning_condition,
            innovation_ability:innovation_ability,
            social_practice:social_practice,
            mixed_ability:mixed_ability,
            application_status:1,
            date:db.serverDate()
          }
        })
          return {success:true,message:event.data}
      }catch(error){
          console.error(error);
          return{success:false,message:"error:"+error}
      }
    }
    else{
      return {success:false,message:"失败"}
    }
  }catch(error){
    return{success:false,message:"error1:"+error}
  }
};

